package cn.gxa.j229.bug.finance.service.borrowing.impl;

import cn.gxa.j229.bug.finance.mapper.LoanMapper;
import cn.gxa.j229.bug.finance.mapper.TbCheckMapper;
import cn.gxa.j229.bug.finance.pojo.Loan;
import cn.gxa.j229.bug.finance.pojo.TbCheck;
import cn.gxa.j229.bug.finance.service.borrowing.LoanService;
import cn.gxa.j229.bug.finance.service.borrowing.TbCheckService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("tbCheckService")
public class TbCheckServiceImpl implements TbCheckService {
    @Resource
    TbCheckMapper tbCheckMapper = null;
    @Resource
    LoanService loanService = null;

    @Override
    public int deleteById(Integer id) {
        return tbCheckMapper.deleteById(id);
    }

    @Override
    public int insert(TbCheck record) {
        record.setAudittime(new Date());
        return tbCheckMapper.insert(record);
    }

    @Override
    public int insertSelective(TbCheck record) {
        record.setAudittime(new Date());
        /**
         * 判断初审是否通过
         * pass=1为通过
         * pass = 0为不通过
         */
        if(record.getPass()==1){
            loanService.updateByNumPass(record.getNum());
        }else{
            loanService.updateByNumUnPass(record.getNum());
        }
        return tbCheckMapper.insertSelective(record);
    }

    @Override
    public TbCheck selectById(Integer id) {
        return tbCheckMapper.selectById(id);
    }

    @Override
    public int updateByIdSelective(TbCheck record) {
        record.setAudittime(new Date());
        /**
         * 判断初审是否通过
         * pass=1为通过
         * pass = 0为不通过
         */
        if(record.getPass()==1){
            loanService.updateByNumPass(record.getNum());
        }else{
            loanService.updateByNumUnPass(record.getNum());
        }
        return tbCheckMapper.updateByIdSelective(record);
    }

    @Override
    public int updateById(TbCheck record) {
        record.setAudittime(new Date());
        return tbCheckMapper.updateById(record);
    }

    @Override
    public List<Map<String, Object>> findById(Integer id) {
        return tbCheckMapper.findById(id);
    }

    @Override
    public int findByNum(String num) {
        return tbCheckMapper.findByNum(num);
    }

    @Override
    public int deleteByNum(String num) {
        return tbCheckMapper.deleteByNum(num);
    }

}
